import {createApp} from 'vue'
import App from './App.vue'
import router from './router/router.ts'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import '@/assets/styles/init.scss'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import {sendGlobalMessage} from "@/hooks/globalmessage.ts";
import '@/assets/styles/commonStyle.scss'
import {BusinessError, CompUserError} from "@/common/comTypes/errorType.ts";
import {GlobalMessage, MessageType} from "@/event/eventglobalmessage.ts"; //导入全局样式
const app = createApp(App)

app.use(router)
app.use(ElementPlus)
app.provide('sendGlobalMessage', sendGlobalMessage)
app.config.errorHandler = (error, instance, info) => {

    //全局异常处理
    if (error instanceof BusinessError) {
        //通用业务异常
        console.error("全局异常处理，异常信息:"+error.message)
        sendGlobalMessage(new GlobalMessage().buildType(MessageType.ERROR).buildMessage(error.message))
    } else if (error instanceof CompUserError) {
        //组件使用错误
        console.error("全局异常处理，异常信息:"+error.message)
        sendGlobalMessage(new GlobalMessage().buildType(MessageType.WARN).buildMessage(error.message))
    }
};
//注册icon为全局组件
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
app.mount('#app')
